<?php

namespace app\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\View;

class DataTest extends BaseController
{
  public function index()
  {
    // $rs = Db::table("tp_user")->select();
    $rs = Db::connect("mysql")->table("tp_user")->select();
    return json($rs);
  }

  public function select()
  {
    $rs = Db::connect("mysql")->table("tp_user")->select();
    $na = "示例姓名";
    $age = 25;
    $g = "male";

    View::assign("user", $rs);
    View::assign("name", $na);
    View::assign("age", $age);
    View::assign("gender", $g);

    $ga = [
      "user" => $rs,
      "name" => $na,
      "age" => $age,
      "gender" => $g
    ];
    return View::fetch("select", $ga);
  }

  public function search()
  {
    $rs = Db::name("user")->select();
    return json($rs);
  }
}
